﻿using System;
using System.Globalization;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;

namespace Coding4Fun.WheresMyCar
{
	public class DistanceConverter : IValueConverter
	{

		#region IValueConverter Members

		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
            if (value == null ) return "";

            double val = Double.Parse(value.ToString());
		    string unit;
            if( WheresTheCarSettings.Instance.MeasurementMode == MeasurementMode.Imperial)
            {
                unit = "miles";
                val = (val*3.2808399)/5280.0;
            }
            else
            {
                unit = "km";
                val /= 1000.0;
            }

            return string.Format("{0:0.00} {1}", val, unit);
		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			throw new NotImplementedException();
		}

		#endregion
	}

    public class FormatConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if( value == null || parameter == null) return value;

            return string.Format(parameter.ToString(), value);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
